<?php
/**
 * Created by PhpStorm.
 * Date: 2021/11/20
 * Time: 17:51
 */

namespace ApiSdk\SmallRedBook\Servers\Order;


use ApiSdk\SmallRedBook\Servers\Request\SmallRedBookBaseRequest;



class SmallRedBookOrder extends SmallRedBookBaseRequest
{
    /**
     * 订单列表
     * author: Linqh
     * Date  2021/11/20 18:08
     * @param array $param 订单列表参数
     * @return mixed
     */
    public function getPackageList($param = [])
    {
//        $param = [
//            'startTime'     => '',  // 必填  时间范围起点
//            'endTime'       => '',  // 必填  时间范围起点
//            'timeType'      => '',  // 必填  startTime/endTime对应的时间类型，1 创建时间 限制 end-start<=24h、2 更新时间 限制 end-start<=30min 倒序拉取 最后一页到第一页
//            'packageType'   => '',  // 非必填 包裹类型，0/null 全部 1 普通 normal 2 定金预售 3 全款预售 4 延迟发货 5 换货补发
//            'packageStatus' => '',  // 非必填 包裹状态，0全部 1已下单待付款 2已支付处理中 3清关中 4待发货 5部分发货 6待收货 7已完成 8已关闭 9已取消 10换货申请中
//            'pageNo'        => '',  // 页码
//            'pageSize'      => '',  // 每页面总数
//        ];
        $this->setCommonParam('package.getPackageList');
        $this->addParams($param);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }


    /**
     * 订单详情
     * author: YZY
     * date: 2021/11/22 15:53
     * @param array $param
     * @return mixed
     */
    public function getPackageDetail($param = [])
    {
//        $param = [
//            'packageId' => '',  // 必填  包裹号
//        ];
        $this->setCommonParam('package.getPackageDetail');
        $this->addParams($param);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }


    /**
     * 获取订单收件人信息
     * author: YZY
     * date: 2021/11/22 16:01
     * @param array $param
     * @return mixed
     */
    public function getPackageReceiverInfo($param = [])
    {
//        $param['receiverQueries'] = [        // 必填   收件人详情查询列表，上限20，请务必在发货前调用一次避免用户修改导致不一致
//            [
//                'packageId'=>'',            //必填   包裹号
//                'openAddressId'=>''         //必填    详情接口返回，标识此单收件人信息
//            ],
//        ];
        $this->setCommonParam('package.getPackageReceiverInfo');
        $this->addParams($param);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }


    /**
     * 修改订单备注
     * author: YZY
     * date: 2021/11/22 16:10
     * @param array $param
     * @return mixed
     */
    public function modifySellerMarkInfo($param = [])
    {
//        $param = [
//            "packageId"=>'',          //string  必填   包裹号
//            "sellerMarkNote"=>'',     //string  必填   商家备注内容
//            "operator"=>'',           //string  必填  操作人
//            "sellerMarkPriority"=>'', //integer  必填  商家标记优先级，ark订单列表展示旗子颜色 1灰旗 2红旗 3黄旗 4绿旗 5蓝旗 6紫旗
//        ];
        $this->setCommonParam('package.modifySellerMarkInfo');
        $this->addParams($param);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

    /**
     * 订单发货
     * author: YZY
     * date: 2021/11/22 16:09
     * @param array $param
     * @return mixed
     */
    public function packageDeliver($param = [])
    {
//        $param = [
//            "packageId"=>'',            //string   必填  包裹号
//            "expressNo"=>'',            //string   必填   快递单号
//            "expressCompanyCode"=>'',   //string   必填   快递公司编码
//            "expressCompanyName"=>'',   //string   非必填  快递公司名称
//            "deliveringTime"=>'',       //integer  非必填  发货时间 不传默认当前时间（ms）
//            "unpack"=>"",               //boolean  非必填  是否拆包发货 true 拆包发货 false正常发货
//            "itemIdList"=>[],           //array<string>  非必填  拆包发货时 必填，使用订单详情itemList一层的的itemId
//        ];
        $this->setCommonParam('package.packageDeliver');
        $this->addParams($param);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"message"=>$response['error_msg']];
        }
        return ['status'=>true,"message"=>"获取成功"];
    }


    /**
     * 修改快递单号
     * author: YZY
     * date: 2021/11/22 16:13
     * @param array $param
     * @return mixed
     */
    public function modifyPackageExpressInfo($param = [])
    {
//        $param=[
//            "packageId"=>'',             //string   必填   包裹号
//            "expressNo"=>'',             //string   必填   快递单号
//            "expressCompanyCode"=>'',    //string   必填   快递公司编码
//            "expressCompanyName"=>'',    //string   非必填  快递公司名称
//            "deliveryPackageIndex"=>'',  //integer  非必填  修改拆包包裹快递单号必传
//        ];
        $this->setCommonParam('package.packageDeliver');
        $this->addParams($param);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }





    /**
     * 订单物流轨迹
     * author: YZY
     * date: 2021/11/22 16:14
     * @param array $param
     * @return mixed
     */
    public function getPackageTracking($param = [])
    {
//        $param = [
//            'packageId' => '',  // 必填  包裹号
//        ];
        $this->setCommonParam('package.getPackageTracking');
        $this->addParams($param);
        $response =$this->post();
        if($response['success']==false || $response['error_code']!=0){
            return ['status'=>false,"data"=>[],"message"=>$response['error_msg']];
        }
        return ['status'=>true,"data"=>$response['data'],"message"=>"获取成功"];
    }

}
